package com.gree.changying.activity.mainactivity.framgent.homefrm;


import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.ViewPager;

import com.gree.changying.R;
import com.gree.changying.activity.base.BasePageFragment;
import com.gree.changying.activity.mainactivity.framgent.homefrm.tuijian.adapter.ViewPagerAdapter;
import com.gree.changying.view.AutoViewPager;
import com.gree.changying.widget.tablayout.jtablayout.tab.Tab;
import com.gree.changying.widget.tablayout.widget.JTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class BifenFrm extends BasePageFragment {
    @Override
    protected void initView(View view) {
        ButterKnife.bind(this,view);
        init();
        initHaoliao();
    }

    @Bind(R.id.haoliaoTab)
    JTabLayout haoliaoTab;
    @Bind(R.id.haoliaoPager)
    AutoViewPager haoliaoPager;
    ViewPagerAdapter haoliaoAdapter;
    private void initHaoliao(){
        haoliaoAdapter = new ViewPagerAdapter();
        haoliaoPager.setAdapter(haoliaoAdapter);
        haoliaoPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                haoliaoTab.selectTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        haoliaoTab.addOnTabSelectedListener(new JTabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(@NonNull Tab var1) {
                haoliaoPager.setCurrentItem(var1.getPosition());
            }

            @Override
            public void onTabUnselected(@NonNull Tab var1) {

            }

            @Override
            public void onTabReselected(@NonNull Tab var1) {

            }
        });
        initHaoliaoData();
    }
    private String[] haoliao = {"球探比分","体球比分","7M比分","雷速足球"};
    private void initHaoliaoData(){
        List<View> views = new ArrayList<>();
        for(String s:haoliao){
            Tab tab = haoliaoTab.newTab().setTitle(s);
            tab.setTitleColor(getResources().getColor(R.color.tabHaoliao)
                    ,getResources().getColor(R.color.tabHaoliaoP));
            haoliaoTab.addTab(tab);
            View tView =  LayoutInflater.from(mContext).inflate(R.layout.view_zhishu, null);
            views.add(tView);
        }
        haoliaoAdapter.update(views);
        haoliaoPager.setCurrentItem(0);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.frm_bifen;
    }

    private void init(){

    }
}
